package com.zhc.dejingapi.config;


import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.jdbc.DataSourceBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.datasource.DataSourceTransactionManager;
import org.springframework.transaction.PlatformTransactionManager;

import javax.sql.DataSource;

@Configuration
public class dingDataDbConfig {

    @ConfigurationProperties(prefix = "spring.datasource.dingdatadb")
    @Bean("dingDataDataSource")
    public DataSource dingDataDataSource() {
        return DataSourceBuilder.create().build();
        //return new DruidDataSource();
    }

    @Bean("dingDataTransactionManager")
    public PlatformTransactionManager dingDataTransactionManager(@Qualifier("dingDataDataSource") DataSource dataSource) {
        return new DataSourceTransactionManager(dataSource);
    }

    @Bean("dingDataJdbcTemplate")
    public JdbcTemplate jdbcTemplate(@Qualifier("dingDataDataSource") DataSource dataSource) {
        return new JdbcTemplate(dataSource);
    }
}
